<?php

namespace App\Utils;

class HelperUtil
{
    const ORDER_DESC = 'descending';
    const ORDER_ASC = 'ascending';

    /**
     * 成功返回JSON数据
     * @param $data
     * @param string $message
     * @param int $code
     * @return \Illuminate\Http\JsonResponse
     */
    public static function responseSuccess($data, $message = '成功', $code = 0)
    {
        return response()->jsonp(request()->get('callback'), [
            'code' => $code,
            'data' => $data,
            'message' => $message
        ]);
    }

    /**
     * 失败返回JSON数据
     * @param string $message
     * @param int $code
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public static function responseError($message = '请求失败', $code = 1, $data = [])
    {
        return response()->jsonp(request()->get('callback'), [
            'code' => $code,
            'data' => $data,
            'message' => $message
        ]);
    }
}